package com.one.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.one.bean.Orders;
import com.one.mapper.OrderInfoMapper;
import com.one.mapper.OrderMapper;
import com.one.service.QueryOrderService;
import com.one.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author ShiWen
 * @date 2022/1/18 8:55
 * @Version 1.0
 * @Description TODO
 */
@Service
public class QueryOrderServiceImpl implements QueryOrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Override
    public List<Orders> queryAllOrder(Integer userId) {
        LambdaQueryWrapper<Orders> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //插入条件
        lambdaQueryWrapper.eq(Orders::getUserId,userId).orderByDesc(Orders::getCreateDate);
        return orderMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public List<Orders> queryOrderByStatus(Integer userId, Integer status) {
        LambdaQueryWrapper<Orders> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Orders::getUserId,userId);
        lambdaQueryWrapper.eq(Orders::getStatus,status).orderByDesc(Orders::getCreateDate);
        return orderMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public OrderVo queryOrderById(Integer userId, Integer orderId) {

        return orderMapper.selectOrderById(userId, orderId);
    }

    @Override
    public OrderVo queryOrderByNo(String orderNo) {
        return orderMapper.selectOrderByNo(orderNo);
    }

    @Override
    public int insertExpressNo(String orderNo, String expressNo) {
        LambdaQueryWrapper<Orders> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Orders::getOrderNo,orderNo);
        Orders orders = new Orders();
        orders.setLogisticCode(expressNo);
        orders.setStatus(3);
        return orderMapper.update(orders,lambdaQueryWrapper);
    }
}
